package com.sxt.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;

import com.sxt.dao.GoodsDao;
import com.sxt.domain.Goods;
import com.sxt.model.EasyUIData;
import com.sxt.service.GoodsService;

@Service
public class GoodsServiceImpl implements GoodsService {

	@Autowired
	private GoodsDao goodsDao;
	
	/**
	 * 把新增或者修改的，在最前面显示
	 */
	@Override
	public EasyUIData queryAll(Integer page, Integer size) {
		Pageable pageable  = new PageRequest(page, size, Direction.DESC, "updateTime"); 
		Page<Goods> goodsPage = goodsDao.findAll(pageable);
		long total = goodsPage.getTotalElements();
		List<Goods> content = goodsPage.getContent();
		return new EasyUIData(total, content);
	}

}
